package com.trainbook.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.trainbook.common.result.JsonResult;
import com.trainbook.entity.User;
import com.trainbook.mapper.UserMapper;
import com.trainbook.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author Dempsey
 * @since 2020-11-27
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {


    /**
     * 登录
     *
     * @param username
     * @param password
     * @return
     */
    @Override
    public JsonResult login(String username, String password) {
        QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
        userQueryWrapper.eq("userName", username);
        List<User> userList = list(userQueryWrapper);
        if (userList.size() == 0) {
            return JsonResult.error("没有此用户");
        }
        for (User user : userList) {
            if (user.getPassWord().equals(password)) {
                return JsonResult.success("登录成功");
            }
        }
        return JsonResult.error("用户密码错误");
    }

}
